using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QuanLyKhachSan.DTO;
using NUnit.Framework;
using QuanLyKhachSan;

namespace UnitTest
{
    public class clsTestQuyDinh: clsTest
    {
        public bool Assert_Clauses(DataTable expected, QuyDinhDTO actual)
        {
            if (expected.Rows.Count > 0)
            {
                DataRow dr = expected.Rows[0];
                Assert.AreEqual(float.Parse(dr["phuThu"].ToString()), actual.PhuThu, "donGia not the same");
                Assert.AreEqual((int)dr["soKhachToiDa"], actual.SoKhachToiDa, "SoKhachToiDa not the same");
                return true;
            }

            return false;
        }
        [Test]
        public void TestUpdate()
        {
            //su dung he thong en-US
            System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            QuyDinhDTO qd = new QuyDinhDTO();
            qd.PhuThu = float.Parse("0.26");
            qd.SoKhachToiDa = 4;

            bool kq = QuyDinhDAO.Update(qd);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("phuThu", qd.PhuThu);
            para.Add("soKhachToiDa", qd.SoKhachToiDa);

            expectedData = select_DataTable("QuyDinh", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert_Clauses(expectedData, qd);
                Assert.IsTrue(kq);
            }
            System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
        }
    }
}
